package com.android.luhnchecking;

public class AccountUtils {
	/**
	 * Check length of account number
	 * 
	 * @param number
	 *            Account number
	 * @return when number has 11 digit
	 */
	public static boolean isValidNumber(final LuhnNumber number) {
		String value = number.getValue();
		boolean isValid = (value != null) && (11 == value.length());
		return isValid;
	}

	/**
	 * Check number is pass or fail
	 * 
	 * @param Account
	 *            number
	 * @return true when pass
	 */
	public static boolean check(final LuhnNumber number) {
		boolean passed = true;
		int sum = 0;
		String value = number.getValue();

		for (int i = 0; i < 11; ++i) {
			int n = value.charAt(i) - '0';
			if (i % 2 == 0) {
				sum += n;
			} else {
				n += n;
				sum += (n / 10) + (n % 10);
			}
			System.out.println(n);
		}

		passed = ((sum % 10) == 0);

		return passed;
	}
}
